class SocketServer{

    constructor(url){
        this.ws = new WebSocket(url)
    }

    getTarget(){
        return this.ws;
    }

    registeEvent(event,handler){
        this.ws[event]=handler
    }

    sendMsg(data){
       this.ws.send(data); 
    }

    close(){
        this.ws.close();
    }

    
}
const EventType={
    OPEN:"onopen",
    ERROR:"onerror",
    MESSAGE:"onmessage",
    CLOSE:"onclose"
}

module.exports = {
    SocketServer,
    EventType
}